<!--
 * @Author: BlueSkyDream
 * @Date: 2022-10-11 08:11:19
 * @LastEditTime: 2023-03-30 16:24:27
 * @Description: 待填充
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div01{
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 300px;
        }
        #result{
            width: 200px;
            height: 200px;
            border: 1px solid  pink;
        }
    </style>
</head>
<body>
    <div id="div01">
        <button>点我发送数据</button>
        <div id="result"></div>
    </div>
    <script>
        // 1.获取html结构相应节点
        const textarea=document.querySelector("#result");
        const button=document.getElementsByTagName("button")[0];
        button.onclick=()=>{
            // //2. 创建xhr对象
            // let xhr=new XMLHttpRequest();
            // // 3. 创建http 请求
            // xhr.open('GET',"http://127.0.0.1:8070/xhr-get?a=100&b=200");
            // // 4. 发送请求
            // xhr.send();
            // // 5. 处理服务器端请求返回结果
            // xhr.onreadystatechange=function(){
            //     if(xhr.readyState==4){
            //         if(xhr.status>=200&&xhr.status<300){
            //             textarea.innerHTML=xhr.responseText;
            //             console.log(xhr)
            //         }
            //     }
            // }
             let  xhr=new  XMLHttpRequest()
             xhr.open("GET","http://127.0.0.1:3000/xhr-get?a=100&b=200")
             xhr.send()
             xhr.onreadystatechange=()=>{
                if(xhr.readyState==4){
                  if(xhr.status>=200&&xhr.status<300){
                    textarea.innerHTML=xhr.responseText;  
                  }
                }
                
             }
        }
        
    </script>
</body>
</html>